/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { Request } from './Request';
import { Response } from './Response';
import { TimeUnit } from './utils/TimeUnit';
import { Connection } from './Connection';
import { Call } from './Call';


export interface Interceptor {
    intercept(chain: Chain): Promise<Response>
    /**
      * Constructs an interceptor for a lambda. This compact syntax is most useful for inline
      * interceptors.
      *
      * ```
      * val interceptor = Interceptor { chain: Interceptor.Chain ->
      *     chain.proceed(chain.request())
      * }
      * ```
      */
    // inline operator fun invoke(crossinline block: (chain: Chain) -> Response): Interceptor =
    //     Interceptor { block(it) }
}

export interface Chain {
    request(): Request

    proceed(request: Request): Promise<Response>
    /**
     * Returns the connection the request will be executed on. This is only available in the chains
     * of network interceptors; for application interceptors this is always null.
     */
    connection(): Connection | null

    call(): Call

    connectTimeoutMillis(): number

    withConnectTimeout(timeout: number, unit: TimeUnit): Chain

    readTimeoutMillis(): number

    withReadTimeout(timeout: number, unit: TimeUnit): Chain

    writeTimeoutMillis(): number

    withWriteTimeout(timeout: number, unit: TimeUnit): Chain
}